﻿using System;
using System.IO;
using System.Text;
using System.Threading;

using HslCommunication;
using HslCommunication.Core.Pipe;
using HslCommunication.Profinet.Melsec;
using HslCommunication.Profinet.Siemens;

internal class Program
{
    private static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");


        PipeTcpNet pipe = new PipeTcpNet("192.168.1.233", 102);
        pipe.ConnectTimeOut = 5000;
        pipe.ReceiveTimeOut = 5000;

        SiemensS7Net siemensTcpNet = new SiemensS7Net(SiemensPLCS.S1200);
        siemensTcpNet.Rack = 0;
        siemensTcpNet.Slot = 0;
        siemensTcpNet.CommunicationPipe = pipe;

        OperateResult connect = siemensTcpNet.ConnectServer();


        if (connect.IsSuccess)
        {
            int cycle = 3;
            while (cycle-- >0)
            {

                System.Threading.Thread.Sleep(1000);
                OperateResult<short> read = siemensTcpNet.ReadInt16("DB5.2");
                if (read.IsSuccess)
                {
                    Console.WriteLine($"{DateTime.Now} Read Success:{read.Content}");
                }
                else
                {
                    Console.WriteLine($"{DateTime.Now} Read failed:{read.Message}");
                }

            }

        }

        siemensTcpNet.ConnectClose();


    }
}